const fs = require("fs");

const fileList = [
  // {
  //   name: "BaseResult",
  //   type: "single"
  // },
  // {
  //   name: "VO",
  //   type: "multiple"
  // },
  // {
  //   name: "ApplicationYml",
  //   type: "single"
  // },
];

for (let i = 0; i < fileList.length; i++) {
  const item = fileList[i];
  const tplVmName = `${item.name}.tpl.vm`;
  const vMName = `${item.name}.vm`;
  let tplContent;
  if (item.type === "single") {
    // 全局只要一个文件
tplContent = `
#set($entityModel = {"package":$model.package})

##生成xxxx.java，如果目标文件存在，替换
$processor.generate("\${model.tplPath}/${item.name}.vm", "\${model.targetPath}/${item.name}.java", true,
$entityModel)
`
  } else {
    // 全局有多个文件
tplContent = `
## 此时，model是tpl1.jm.vm中传入的cfg
#macro(name $rawName)
\${rawName.substring(0,1).toLowerCase()}\${rawName.substring(1)}##
#end
#foreach($table in $model.db.tables)

    #set($entityModel = {"table" : $table, "package":$model.package})
    #set($entityModel.className = \${table.className})

    ##生成xxxx.java，如果目标文件存在，替换
    $processor.generate("\${model.tplPath}/${item.name}.vm", "\${model.targetPath}/#name(\${table.className})/\${table.className}${item.name}.java", true, $entityModel)
#end
`
  }
  fs.writeFileSync(tplVmName, tplContent, function (err) {
    if (err) return console.log(err);
  });
  fs.writeFileSync(vMName, "", function (err) {
    if (err) return console.log(err);
  });
}

// ${model.package}

// ${model.className}
// #name(${model.className})